import re
import sqlite3

file = open('./dict-zi.js', mode='r', encoding='utf8')
text = file.read()
text_list = re.findall(r'dict\[(.*)\]\s+=\s+"(.*)"', text)

connection = sqlite3.connect('database.db')
cursor = connection.cursor()
cursor.execute('''
    CREATE TABLE IF NOT EXISTS word (
        id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
        word TEXT NOT NULL UNIQUE ,
        spell TEXT NOT NULL
    )
''')
for key,value in text_list:
    key = chr(int(key,16))
    sql = '''
          REPLACE INTO word (word, spell) VALUES ('%s', '%s')
      ''' % (key, value)
    cursor.execute(sql)

connection.commit()
connection.close()
print('完成')
